<#include "/common/head.html"/>    
    <table id="dg"></table>
    <div id="tb" style="padding:2px 5px;">
        <div class="wrap_search">
	
				            <span class="search_item">
						        <span class="item_text">商品名称: </span>
						        <span class="item_obj">
						  <!--          <input class="easyui-textbox" type="text" name="goodsname" id="goodsname" value=""/> -->
						           <input class="easyui-combobox" type="text" name="goodsname" value="" id="goodsname" data-options="valueField:'id', textField:'goodsname'" />
						        </span>   
						    </span>
						     
        <div style="text-align: riagt; margin:6px;">           
                <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="glyphicon-search"  onclick="zcurdSearch(this)">搜索</a> 
        </div> 
      </div>
      </div>


			            

<script type="text/javascript">
var datagrid = $("#dg");

$(function() {
	datagrid.datagrid(dgOptions);
	// 加载商品名称
	$("#goodsname").combobox({
		onChange:function(){
			queryGoodsName($("#goodsname").combobox('getText'));
		}
	});
	
});



// 页面加载商品名称
function queryGoodsName(value) {
	
	$.post("getGoodsName", //url
	{
		goodsname : value
	}, function(data) {
		//$("#goodsName").combobox("clear");
		if(data!="ok"){
			$("#goodsname").combobox("loadData", data); //callback
		}
	
	});
}

var dgOptions = {
        rownumbers:true,
    	fit:true,
    	border:false,
    	striped:true,
        rownumbers:true,
    	url:'listOnline',
    	method:'post',
    	toolbar:'#tb',
    	pageSize: 10,
    	pagination:true,
    	multiSort:true,
    	singleSelect:true,
        queryParams: getInitParam(),
        columns: [[
                   //小图地址smallpic，当前库存量STOREDCOUNT？，商品类别goodstype ，商品售价同步另一个表
				{field:'goodsid', title:'商品ID', width:300}
	           	 ,{field:'goodsname', title: '商品名称', width:300}
		         ,{field:'goodstype',title: '商品类别', width:300,
		        	 formatter : function(value, rowData,rowIndex) {  
	                     if(value==0){  
	                         return "实物";  
	                     }
	                       if(value==1){  
	                    	   show=1;
	                           return "数字 ";  
	                     } 
	        		 }
		         }	         
	           	 ,{field:'marketprice', title: '商品售价', width:300,formatter:cent2Dollar}          
	           	,{field:'tf', title: '操作', width:300,
	           		 formatter: function(value,row,index){
	           			        return '<a style="color:blue" href="javascript:void(0)" onclick=add(\"'+row.productid+'\") >添加方案</a>';
	           			      },	
	           	} 
	           ]]
	};
/* function add(goods,goodsname) {
	top.openWindow("倍数修改", getCurrUrl("add") + "?goods=" + goods+"&goodsname="+goodsname, {size: '400x200'});
} */

$(function() {
	datagrid.datagrid(dgOptions);
});
function zcurdSearch() {
/* 	var param = zcurdGetParam(); */
	var param={
	goodsname:$("#goodsname").combobox("getText")
}
	datagrid.datagrid("load", param);
}
/* function goodsPreview(value,row,index){
	var rowsSel = datagrid.datagrid("getSelections");
	if(rowsSel.length != 1) {
		showWarnMsg("请选择一条数据！");
		return;
	}
	var goodsid = rowsSel[0].goodsid;
	var merid = rowsSel[0].merid;
	window.open(goodsurl+'/'+goodsid+'/'+merid+'.htm');
} */

function formatPrice(value,row,index){
	return (value/100).toFixed(2);
}

function formatState(value,row,index){
	if(value == 0){
		return "下架";
	}else if(value == 1){
		return "上架";
	}
}

function zcurdGetParam() {

/* 	$("#tb :input[name]").each(function(i, item) {
		if($(item).val()) {
			param[$(item).attr("name")] = $(item).val().trim();	
		}
	}); */
}

function getInitParam() {
	 var param = {
		/* 	 goodsname:$("#goodsname").combobox("getText"); */
	 };
	/* $("#tb :input[name]").each(function(i, item) {
		if($(item).val()) {
			param["queryParams[" + $(item).attr("name") + "]"] = $(item).val().trim();	
		}
	});  */
	return param;
}

var initPara = zcurdGetParam();

function update() {
	var rowsSel = datagrid.datagrid("getSelections");
	 if(rowsSel.length != 1) {
		showWarnMsg("请选择一条数据！");
		return;
	} 
	var productid = rowsSel[0].productid;
	var auditstate = rowsSel[0].auditstate;
	if(auditstate==0){
		showWarnMsg("商品正在审核中,无法进行修改！");
		return;
	}
	location.replace('updatePage?productid='+productid);
}

function add(productid) {
 	var rowsSel = datagrid.datagrid("getSelections");
	top.window.subPage.loadCurrDatagrid = function(data) {
      showMsg("增加成功！"); 
		datagrid.datagrid("load");
	}
	top.openWindow("管理-增加", getCurrUrl("updatePage") + "?productid=" + productid, {size: '800x600'}); 
}

/**
 * 打开子页
 */
var _openSubPageFlag = false;
function _openSubPage(pageUrl) {
	if(!_openSubPageFlag) {
		$("#subLayout").layout("expand", "east");
		setTimeout(function() {
			$("#subIframe").attr("src", pageUrl);
		}, 600);
		_openSubPageFlag = true;
	}else {
		$("#subIframe").attr("src", pageUrl);
	}
}

</script>
<#include "/common/dialogWindow.html"/>
<#include "/common/foot.html"/>